home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-src / vcpp / unix.c < prev   
C/C++ Source or Header  |  1999-01-01  |  4KB  |  118 lines

  1. #include <stdio.h>
  2. #include <stddef.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "cpp.h"
  6.  
  7. extern  int getopt(int, char *const *, const char *);
  8. extern  char    *optarg, rcsid[];
  9. extern  int     optind;
  10. int     verbose;
  11. int     Mflag;  /* only print active include files */
  12. char    *objname; /* "src.$O: " */
  13. /*vb:   */
  14. int     Cplusplus = 0;
  15.  
  16. void
  17. setup(int argc, char **argv)
  18. {
  19.         int c, fd, i;
  20.         char *fp, *dp;
  21.         Tokenrow tr;
  22.         extern void setup_kwtab(void);
  23.  
  24.         setup_kwtab();
  25.         while ((c = getopt(argc, argv, "MNOVv+I:D:U:F:lg")) != -1)
  26.                 switch (c) {
  27.                 case 'N':
  28.                         for (i=0; i<NINCLUDE; i++)
  29.                                 if (includelist[i].always==1)
  30.                                         includelist[i].deleted = 1;
  31.                         break;
  32.                 case 'I':
  33.                         for (i=NINCLUDE-2; i>=0; i--) {
  34.                                 if (includelist[i].file==NULL) {
  35.                                         includelist[i].always = 1;
  36.                                         includelist[i].file = optarg;
  37.                                         break;
  38.                                 }
  39.                         }
  40.                         if (i<0)
  41.                                 error(FATAL, "Too many -I directives");
  42.                         break;
  43.                 case 'D':
  44.                 case 'U':
  45.                         setsource("<cmdarg>", -1, optarg);
  46.                         maketokenrow(3, &tr);
  47.                         gettokens(&tr, 1);
  48.                         doadefine(&tr, c);
  49.                         unsetsource();
  50.                         break;
  51.                 case 'M':
  52.                         Mflag++;
  53.                         break;
  54.                 case 'v':
  55.                         fprintf(stderr, "%s %s\n", argv[0], rcsid);
  56.                         break;
  57.                 case 'V':
  58.                         verbose++;
  59.                         break;
  60.                 case '+':
  61.                         Cplusplus++;
  62.                         break;
  63.                 default:
  64.                         break;
  65.                 }
  66.         dp = ".";
  67.         fp = "<stdin>";
  68.         fd = 0;
  69.         if (optind<argc) {
  70.                 if ((fp = strrchr(argv[optind], '/')) != NULL) {
  71.                         int len = fp - argv[optind];
  72.                         dp = (char*)newstring((uchar*)argv[optind], len+1, 0);
  73.                         dp[len] = '\0';
  74.                 }
  75.                 fp = (char*)newstring((uchar*)argv[optind], strlen(argv[optind]), 0);
  76.                 if ((fd = open(fp, 0)) <= 0)
  77.                         error(FATAL, "Can't open input file %s", fp);
  78.         }
  79.         if (optind+1<argc) {
  80.                 int fdo = creat(argv[optind+1], 0666);
  81.                 if (fdo<0)
  82.                         error(FATAL, "Can't open output file %s", argv[optind+1]);
  83.                 dup2(fdo, 1);
  84.         }
  85.         if(Mflag)
  86.                 setobjname(fp);
  87.         includelist[NINCLUDE-1].always = 0;
  88.         includelist[NINCLUDE-1].file = dp;
  89.         setsource(fp, fd, NULL);
  90. }
  91.  
  92.  
  93.  
  94. /* memmove is defined here because some vendors don't provide it at
  95.    all and others do a terrible job (like calling malloc) */
  96. /*void *
  97. memmove(void *dp, const void *sp, unsigned int n)
  98. {
  99.         unsigned char *cdp, *csp;
  100.  
  101.         if (n<=0)
  102.                 return 0;
  103.         cdp = dp;
  104.         csp = (unsigned char *)sp;
  105.         if (cdp < csp) {
  106.                 do {
  107.                         *cdp++ = *csp++;
  108.                 } while (--n);
  109.         } else {
  110.                 cdp += n;
  111.                 csp += n;
  112.                 do {
  113.                         *--cdp = *--csp;
  114.                 } while (--n);
  115.         }
  116.         return 0;
  117. } */
  118.